package com.leonzhangxf.guava.eventbus;

import com.google.common.eventbus.DeadEvent;
import com.google.common.eventbus.Subscribe;

public class PrintEventListener {

    private String identifier;

    public PrintEventListener(String identifier) {
        this.identifier = identifier;
    }

    @Subscribe
    public void handlePrintEvent(PrintEvent printEvent) {
        System.out.println(String.format("listener listen the event %s", identifier));
        System.out.println(String.format("listener handle the event %s", printEvent.print()));
    }

    @Subscribe
    public void handlePrintEvent(PrintEventImp printEvent) {
        System.out.println(String.format("listener listen the event %s", identifier));
        System.out.println(String.format("listener handle the event %s", printEvent.print()));
    }

    @Subscribe
    public void handlePrintEvent(PrintEventImp2 printEvent) {
        System.out.println(String.format("listener listen the event %s", identifier));
        System.out.println(String.format("listener handle the event %s", printEvent.print()));
    }

    /**
     * 处理没有监听器的事件
     */
    @Subscribe
    public void handleDeadEvent(DeadEvent deadEvent) {
        System.out.println(deadEvent.getEvent().toString());
    }
}
